package com.gopay.common.riskcontrol;

import com.gopay.common.cache.constants.RedisConstants;
import com.gopay.common.riskcontrol.vo.RcLimitCfg;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;

/**
 * Created by zhaojt on 2017/5/24.
 *
 * 额度管理Redis Key Field生成器
 */
@Component
@Lazy
public class RcRedisKeyGen {

    @Autowired
    private RedisConstants redisConstants;

    /**
     * DicRclDirection表缓存数据过期时间，单位秒。
     */
    public static final int DicRclDirectionKeyExpire = 8 * 60 * 60 ;

    /**
     * 个性化:  KEY [param:rcl:${custId}:intTxnCd:acctProd:custType] FILED [payChannel或ALL]  VALUE [List<RcCustLimitConf>字符串]
     * @param custId
     * @param intTxnCd
     * @param acctProd
     * @param custType
     * @return
     */
    public String genCustKey(String custId,String intTxnCd, String acctProd, String custType){
        return redisConstants.getRedisEnvironment() + ":rcl:" + custId + ":"+ intTxnCd + ":" + acctProd + ":" + custType;
    }

    /**
     * 通用:    KEY [param:rcl:common:intTxnCd:acctProd:custType:creditRanks] FIELD [payChannel或ALL]  VALUE [List<RcComLimitConf>字符串]
     * @param intTxnCd
     * @param acctProd
     * @param custType
     * @param creditRanks
     * @return
     */
    public String genComKey(String intTxnCd,  String acctProd, String custType, String creditRanks){
        return redisConstants.getRedisEnvironment() + ":rcl:common:" + intTxnCd + ":" + acctProd + ":" + custType + ":" + creditRanks;
    }

    //构建通用配置前缀，删除用
    public String genComKeyPattern(String intTxnCd,  String acctProd, String custType){
        return redisConstants.getRedisEnvironment() + ":rcl:common:" + intTxnCd + ":" + acctProd + ":" + custType;
    }

    public String genDicRclDirectionKey(){
        return redisConstants.getRedisEnvironment() + ":rcl:DicRclDirection";
    }

    //acctProd::custType::intTxnCd::tranDirection
    public String genDicRclDirectionField(String acctProd, String custType, String intTxnCd, String tranDirection){
        return  acctProd + ":" + custType + ":" + intTxnCd + ":" + tranDirection;
    }

    public RedisConstants getRedisConstants() {
        return redisConstants;
    }

    public void setRedisConstants(RedisConstants redisConstants) {
        this.redisConstants = redisConstants;
    }
}
